package com.topscore.uke.mvp.model;

import com.topscore.uke.mvp.contractors.GetMemberCountContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.retrofit.ApiService;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;
import com.topscore.uke.network.retrofit.NetClient;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2018/3/22.
 */

public class GetMemberCountModel implements GetMemberCountContractor,GetMemberCountContractor.Model {
    ApiService mService;

    private CallBack mCallBack;

    public GetMemberCountModel(CallBack callBack) {
        this.mCallBack = callBack;
        mService = NetClient.getInstance().net().create(ApiService.class);
    }

    @Override
    public void getCount(String role, String loginName) {
        mService.getMemberNumber(role,loginName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<Integer>>(mCallBack) {
                    @Override
                    public void onSuccess(BaseResponse<Integer> response) {
                        mCallBack.onSuccess(response);
                    }
                });
    }
}
